import requestUtil from "@/utils/requestUtil";

const MATERIAL_BASE_URL = "/business/warehouse";

const WarehouseAPI = {
  /** 获取仓库分页数据 */
  getPage(queryParams?: WarehousePageQuery) {
    return requestUtil.get<PageResult<WarehousePageVO[]>>(
      `${MATERIAL_BASE_URL}/loadPage`,
      queryParams
    );
  },

  /**
   * 获取仓库表单数据
   *
   * @param id 仓库ID
   * @returns 仓库表单数据
   */
  getFormData(id: string) {
    return requestUtil.get<WarehousePageVO>(`${MATERIAL_BASE_URL}/load/${id}`);
  },

  /** 添加仓库 */
  create(data: WarehouseForm) {
    return requestUtil.post<WarehousePageVO>(`${MATERIAL_BASE_URL}/add`, data);
  },

  /**
   * 更新仓库
   *
   * @param id 仓库ID
   * @param data 仓库表单数据
   */
  update(data: WarehouseForm) {
    return requestUtil.post<WarehousePageVO>(`${MATERIAL_BASE_URL}/update`, data);
  },

  /**
   * 批量删除仓库，多个以英文逗号(,)分割
   *
   * @param ids 仓库ID字符串，多个以英文逗号(,)分割
   */
  deleteByIds(ids: string) {
    return requestUtil.get<boolean>(`${MATERIAL_BASE_URL}/batchDelete?ids=${ids}`);
  },

  deleteById(id: string) {
    return requestUtil.get<boolean>(`${MATERIAL_BASE_URL}/delete/${id}`);
  },

  loadAll() {
    return requestUtil.get<Array<WarehousePageVO>>(`${MATERIAL_BASE_URL}/loadAll`);
  },
};

export default WarehouseAPI;

/** 分页查询参数 */
export interface WarehousePageQuery extends PageQuery {
  /** 搜索关键字 */
}

/** 分页对象 */
export interface WarehousePageVO {
  /** ID */
  id?: string;
  /** 名称 */
  name?: string;
  /** 编码 */
  code?: string;
  remark?: string;
  address?: string;
}

/** 仓库表单对象 */
export interface WarehouseForm {
  /** ID */
  id?: string;
  /** 名称 */
  name?: string;
  /** 编码 */
  code?: string;
  remark?: string;
  address?: string;
}
